<?php
/*     Description */

class Pldkp_Validate_DateTime extends Zend_Validate_Abstract 
{
    
    const INVALID_DATE = 'invalidDate';

    protected $_messageTemplates = array(
        self::INVALID_DATE => 'The date is invalid'
    );

    protected $format;

    
    public function __construct($format) 
    {
        $this->format = $format;
    }

    
    public function isValid($value) 
    {
        // Make sure that the value can be considered a valid date
        if (!$value || !Zend_Date::isDate($value, $this->format)) {
            $this->_error(self::INVALID_DATE);
            return false;
        }
        
        // Compare if the value is actually formatted acording to the format
        // (isDate does not perform a full format check, it ignores any non numerical characters)
        $date = new Zend_Date($value);
        if ($value !== $date->toString($this->format)) {
            $this->_error(self::INVALID_DATE);
            return false;
        }

        return true;
    }
}